1 /****************************** Module Header ******************************\
2 Module Name: ClassFactory.cpp
3 Project: CppShellExtThumbnailHandler
4 Copyright (c) Microsoft Corporation.
6 The file implements the class factory for the RecipeThumbnailProvider COM class.
8 This source is subject to the Microsoft Public License.
9 See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 All other rights reserved.
12 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 \***************************************************************************/
17 #include "ClassFactory.h"
18 #include "RecipeThumbnailProvider.h"
22 extern long g_cDllRef
;
25 ClassFactory::ClassFactory() : m_cRef(1)
27 InterlockedIncrement(&g_cDllRef
);
30 ClassFactory::~ClassFactory()
32 InterlockedDecrement(&g_cDllRef
);
40 IFACEMETHODIMP
ClassFactory::QueryInterface(REFIID riid
, void **ppv
)
44 if (IsEqualIID(IID_IUnknown
, riid
) ||
45 IsEqualIID(IID_IClassFactory
, riid
))
47 *ppv
= static_cast<IUnknown
*>(this);
59 IFACEMETHODIMP_(ULONG
) ClassFactory::AddRef()
61 return InterlockedIncrement(&m_cRef
);
64 IFACEMETHODIMP_(ULONG
) ClassFactory::Release()
66 ULONG cRef
= InterlockedDecrement(&m_cRef
);
79 IFACEMETHODIMP
ClassFactory::CreateInstance(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
81 HRESULT hr
= CLASS_E_NOAGGREGATION
;
83 // pUnkOuter is used for aggregation. We do not support it in the sample.
84 if (pUnkOuter
== NULL
)
88 // Create the COM component.
89 RecipeThumbnailProvider
*pExt
= new (std::nothrow
) RecipeThumbnailProvider();
92 // Query the specified interface.
93 hr
= pExt
->QueryInterface(riid
, ppv
);
101 IFACEMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
105 InterlockedIncrement(&g_cDllRef
);
109 InterlockedDecrement(&g_cDllRef
);